﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace STX.Domain
{
    [Flags]
    public enum RightsEnum
    {
        制作报价 =1,
        审核报价 =2,

        制作项目成本 =4,
        审核项目成本 = 8,

        制作财务成本 = 16,
        审核财务成本 = 32,

        删除报价 =64,
        修改项目成本 = 128,

    }

    [Flags]
    public enum PositionEnum
    {
        /// <summary>
        /// 管理员
        /// </summary>
        [Field(Name = "管理员")]
        [Auth(RightsEnum.制作报价 | RightsEnum.审核报价 | RightsEnum.制作项目成本 | RightsEnum.审核项目成本 | RightsEnum.制作财务成本 | RightsEnum.审核财务成本 | RightsEnum.删除报价)]
        SystemPower = 1,

        /// <summary>
        /// 执行
        /// </summary>
        [Field(Name = "执行")]
        [Auth(RightsEnum.制作报价 | RightsEnum.制作项目成本)]
        Salesperson = 2,

        /// <summary>
        /// 项目经理
        /// </summary>
        [Field(Name = "项目经理")]
        [Auth(RightsEnum.制作报价 | RightsEnum.制作项目成本 | RightsEnum.审核报价)]
        ProjectManager = 4,

        /// <summary>
        /// 项目总监
        /// </summary>
        [Field(Name = "项目总监")]
        [Auth(RightsEnum.审核项目成本 | RightsEnum.修改项目成本 | RightsEnum.审核报价)]
        CPO = 8,

        /// <summary>
        /// 财务经理
        /// </summary>
        [Field(Name = "财务经理")]
        [Auth(RightsEnum.制作财务成本 | RightsEnum.审核项目成本)]
        FinancialManager = 16,

        /// <summary>
        /// 财务总监
        /// </summary>
        [Field(Name = "财务总监")]
        [Auth(RightsEnum.审核项目成本 | RightsEnum.审核项目成本)]
        CFO = 32,


        /// <summary>
        /// 总经理
        /// </summary>
        [Field(Name = "总经理")]
        [Auth(RightsEnum.审核项目成本 | RightsEnum.审核财务成本)]
        GeneralManager = 64,
    }



    [Flags]
    public enum StepEnum
    {

        [Field(Name = "制作报价")]
        [Step(NextStep = 项目经理审核报价, PrevStep = 制作报价)]
        [MyUser(Role = PositionEnum.ProjectManager, Behave = UserBehave.保存为草稿 | UserBehave.提交审核)]
        制作报价 = 1,

        [Field(Name = "项目经理审核报价")]
        [Step(NextStep = 项目总监审核报价, PrevStep = 制作报价)]
        [MyUser(Role = PositionEnum.ProjectManager, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        项目经理审核报价 = 2,

        [Field(Name = "项目总监审核报价")]
        [Step(NextStep = 制作成本, PrevStep = 制作报价)]
        [MyUser(Role = PositionEnum.CPO, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        项目总监审核报价 = 4,

        [Field(Name = "制作成本")]
        [Step(NextStep = 项目总监审核成本, PrevStep = 制作成本)]
        [MyUser(Role = PositionEnum.Salesperson, Behave = UserBehave.保存为草稿 | UserBehave.提交审核)]
        制作成本 = 8,

        [Field(Name = "项目总监审核成本")]
        [Step(NextStep = 财务经理审核成本, PrevStep = 制作成本)]
        [MyUser(Role = PositionEnum.CPO, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        项目总监审核成本 = 16, 

        [Field(Name = "财务经理审核成本")]
        [Step(NextStep = 财务经理制作成本, PrevStep = 制作成本)]
        [MyUser(Role = PositionEnum.FinancialManager, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        财务经理审核成本 = 32,

        [Field(Name = "财务经理制作成本")]
        [Step(NextStep = 财务总监审核成本, PrevStep = 制作成本)]
        [MyUser(Role = PositionEnum.FinancialManager, Behave = UserBehave.保存为草稿 | UserBehave.提交审核)]
        财务经理制作成本 = 64,


        [Field(Name = "财务总监审核成本")]
        [Step(NextStep = 总经理审核成本, PrevStep = 财务经理制作成本 | 制作成本)]
        [MyUser(Role = PositionEnum.CFO, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        财务总监审核成本 = 128,

        [Field(Name = "总经理审核成本")]
        [Step(NextStep = 总经理审核成本, PrevStep = 财务经理制作成本 | 制作成本)]
        [MyUser(Role = PositionEnum.GeneralManager, Behave = UserBehave.审核成功 | UserBehave.审核失败)]
        总经理审核成本 = 256,

    }


    public enum AuditingEnum
    {
        [Field(Name = "草稿")]
        草稿 = 0,

        [Field(Name = "待审核")]
        待审核 = 10,

        [Field(Name = "审核成功")]
        审核成功 = 20,

        [Field(Name = "审核失败")]
        审核失败 = 30,
    }


    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class StepAttribute : System.Attribute
    {

        public StepEnum NextStep { get; set; }
        public StepEnum PrevStep { get; set; }

    }

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class AuthAttribute : System.Attribute
    {
        public AuthAttribute(RightsEnum rights)
        {
            Rights = rights;
        }

        public RightsEnum Rights { get; private set; }
    }

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class MyUserAttribute : System.Attribute
    {

        public PositionEnum Role { get; set; }
        public UserBehave Behave { get; set; }
    }

    [Flags]
    public enum UserBehave
    {
        保存为草稿 = 1,
        提交审核 = 2,
        审核成功 = 4,
        审核失败 = 8
    }
}
